package _interview100;

import _object.TreeNode;

import java.util.ArrayList;
import java.util.List;

/**
 * 199. 二叉树的右视图
 */
public class No199 {
    private List<Integer> ans;
    private int maxDeep;

    public List<Integer> rightSideView(TreeNode root) {
        ans = new ArrayList<>();
        maxDeep = 0;
        dfs(root, 0);
        return ans;
    }

    private void dfs(TreeNode node, int curDeep) {
        if (node == null) return;
        if (curDeep == maxDeep) {
            ans.add(node.val);
            maxDeep++;
        }
        dfs(node.right, curDeep + 1);
        dfs(node.left, curDeep + 1);
    }
}
